//-----------------------------------------------------------------------------
// A script utility which enables the use Gtk# within F# Interactive (fsi.exe)
//-----------------------------------------------------------------------------
[<AutoOpen>]
module GtkSharp

// Load some common Gtk# assemblies (from /usr/lib/mono/2.0/../gtk-sharp-2.0)
#r "INSERTGTKPATH/gtk-sharp.dll"
#r "INSERTGDKPATH/gdk-sharp.dll"
#r "INSERTGLIBPATH/glib-sharp.dll"
#r "INSERTATKPATH/atk-sharp.dll"

open Gtk

Application.Init()
fsi.EventLoop <- 
 { new Microsoft.FSharp.Compiler.Interactive.IEventLoop with
   member x.Run() = Application.Run() |> ignore; false
   member x.Invoke f = 
     let res = ref None
     let evt = new System.Threading.AutoResetEvent(false)
     Application.Invoke(new System.EventHandler(fun _ _ ->
       res := Some(f())
       evt.Set() |> ignore ))
     evt.WaitOne() |> ignore
     res.Value.Value 
   member x.ScheduleRestart() = () }

